package com.saibo.spider.gather;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.methods.CloseableHttpResponse;

import com.alibaba.fastjson.JSONArray;
import com.saibo.spider.commons.SubmitRedisCommons;
import com.saibo.spider.utils.HttpRequestUtil;
import com.saibo.spider.utils.HttpResponseUtil;
import com.saibo.spider.utils.StringUtil;

public class MouldLetvEpisodeInfo {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		MouldLetvEpisodeInfo a = new MouldLetvEpisodeInfo();
		String data = SubmitRedisCommons.getRedisData("letv_episode_info");
		if(StringUtil.isNullOrEmpty(data))return;
		Map<String,Object> mso = StringUtil.jsonToMap(data);
		String missionData = mso.get("mission").toString();
		String url = "http://v.stat.letv.com/vplay/getIdsInfo?type=vlist&ids="+missionData;
		CloseableHttpResponse httpResponse = HttpRequestUtil.getRequestMethod(url, a.requestHeader("http://www.le.com/ptv/vplay/27416375.html"));
		String json = HttpResponseUtil.getHtml(httpResponse);
		//FileUtil.writeLogToTxt(json, "D:/svbnqigJson.txt");
		Map<String,Object> map = new HashMap<String,Object>();
		long time = System.currentTimeMillis();
		List<Map<String,Object>> lmso = (List<Map<String, Object>>) JSONArray.parseArray(json,map.getClass());
		for (Map<String, Object> map2 : lmso) {
			map2.put("crawler_time", time);
		}
		SubmitRedisCommons.submitRedisData("letv_episode_info_list", StringUtil.objectToJson(lmso));
	}
	
	
	
	public Map<String, String> requestHeader(String referer) {
		Map<String, String> requestHeader = new HashMap<String, String>();
		requestHeader.put("Accept", "*/*");
		requestHeader.put("Accept-Encoding", "gzip, deflate, sdch");
		requestHeader.put("Accept-Language", "zh-CN,zh;q=0.8");
		requestHeader.put("Connection", "keep-alive");
		requestHeader.put("Cookie",
				"vjuids=-3b4c0553b.1596da1d049.0.73c62c24b711b; ark_uuid=58196445727148d894f73efc84b20b83; tj_uuid=-_14842756424192403074; tj_lc=ec3ef18552206eadfdfe4d98f430bb7a; tj_env=1; bd_xid=ec3ef18552206eadfdfe4d98f430bb7a; newVideo=%7B%221%22%3A17%2C%222%22%3A123%2C%223%22%3A165%2C%224%22%3A699%2C%225%22%3A46%2C%228%22%3A0%2C%229%22%3A52%2C%2211%22%3A126%2C%2214%22%3A36%2C%2216%22%3A13%2C%2217%22%3A0%2C%2219%22%3A0%2C%2220%22%3A55%2C%2222%22%3A46%2C%2223%22%3A50%2C%2230%22%3A3192%2C%2232%22%3A0%2C%2233%22%3A0%2C%2234%22%3A0%2C%2235%22%3A0%2C%2236%22%3A9%2C%2238%22%3A0%2C%2239%22%3A0%2C%2240%22%3A0%2C%2242%22%3A0%2C%2243%22%3A0%2C%2245%22%3A10%2C%2246%22%3A0%2C%2247%22%3A0%2C%2248%22%3A0%2C%2249%22%3A0%2C%2250%22%3A0%2C%2251%22%3A0%2C%2252%22%3A0%2C%2253%22%3A0%2C%2254%22%3A0%2C%2255%22%3A0%2C%2260%22%3A0%2C%22200%22%3A0%2C%22333%22%3A0%2C%221009%22%3A1882%2C%221021%22%3A27%2C%221029%22%3A16%2C%221035%22%3A12%7D; sso_curr_country=CN; language=zh-cn; vjlast=1483603038.1484275675.13; currentLeft_miniPlayer=492; currentTop_miniPlayer=722; his_vid=27424673-27434584; tj_v2c=-27424673_2-27416375_2; unLogPlayTime=4");
		requestHeader.put("Host", "v.stat.letv.com");
		requestHeader.put("Referer", referer);
		requestHeader.put("User-Agent",
				"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		return requestHeader;
	}
}
